<?php

namespace ms\modules\article\models;

use Yii;
use common\components\behaviors\ImageBehavior;
use yii\db\Query;
/**
 * This is the model class for table "dh_article_info".
 *
 * @property integer $id
 * @property string $title
 * @property string $content
 * @property string $abstract
 * @property string $author
 * @property integer $img_id
 * @property integer $click_num
 * @property integer $nav_id
 * @property integer $status
 * @property integer $icon
 * @property integer $publish_time
 */
class ArticleInfo extends \yii\db\ActiveRecord
{
	/**
	 * @inheritdoc
	 */
	public function behaviors() {
		return [
				'image' => [
						'class' => ImageBehavior::className()
				]
		];
	}
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'dh_article_info';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['content'], 'required'],
            [['content', 'abstract','type'], 'string'],
            [['img_id', 'click_num', 'nav_id', 'status', 'icon', 'publish_time'], 'integer'],
            [['title'], 'string', 'max' => 255],
            [['author'], 'string', 'max' => 25]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '编号',
            'title' => '文章标题',
            'content' => '文章内容',
            'abstract' => '摘要',
            'author' => '作者',
        	'type' => '文章类型',	
            'img_id' => '图片',
            'click_num' => '点击量',
            'nav_id' => '导航栏目',
            'status' => '状态',
            'icon' => '图标',
            'publish_time' => '发布时间',
        ];
    }
    /**
     * @param unknown $status
     * @return string
     * @return: string
     * @author: admin
     * @date: 2015年8月24日下午6:13:15
     * @modified_date: 2015年8月24日下午6:13:15
     * @modified_user:	sunkouping
    */
    public static function getInfoStatus($status){
    	if($status==1){
    		return '生效';
    	}else{
    		return '失效';
    	}
    }
    /**
     * @des:获取招商加盟和热销行情大图区171
     * @return: return_type
     * @author: wei.xie
     * @date: 2015年9月2日上午11:31:56
     * @modified_date: 2015年9月2日上午11:31:56
     * @modified_user:	sunkouping
    */
    public static function getArticleAd(){
    	$ad_info_main= (new Query())->from("{{%sell_ad_position}} a")
    	->leftJoin("{{%sell_ad_info}} b","b.position_id=a.id")
    	->where(['a.id'=>171,'a.is_deleted'=>0])
    	->orderBy('sort asc')
    	->all();
    	if($ad_info_main){
    		return $ad_info_main;
    	}
    }
}
